#ifndef PPGREALPROCESS1_H
#define PPGREALPROCESS1_H
#include "QList"
#include "hrvdataprocess.h"
#include <QObject>

class PPGRealProcess1 : public QObject
{
    Q_OBJECT
private:
    bool RunFlag=true;
    bool SerialState=false;
    int MeasureTime;
    double a_ppg_lp_com[3],b_ppg_lp_com[3];
    double a_ppg_lp[3],b_ppg_lp[3];
    double a_ppg_hp[3],b_ppg_hp[3];
    int SampleNum,SampNumForPI,SN;
    double peakWindowIR[101];
    double peakWindowRED[101];
    int ispeak,smallest;
    int lastPeakIndex,lastValleyIndex;//上一个
    QList<int>peakPos;
    QList<int>RRData;//包含0的rr间期
    double lastPeakValueIR,lastPeakValueRED;
    double lastOnsetValueIR,lastOnsetValueRED;
    double dcIR,dcRed;
    double pi[3];
    unsigned char HR[12];
    unsigned  char movingWindowSize;
    double SpO2[12];
    double perfusion;
    int totalFoundPeak,foundPeak;
    QList<int>PPGForEvaluation;

    int HRVBarLoop;
    HRVDataProcess hrvDataProcess;
    bool StartFlag;
//    double movingWindowHP;
//    double movingWindowRed;
    QList<double>movingWindowHP;
    QList<double>movingWindowRed;
signals:
    void sendSPOX(double ox,int p);
    void sendRR(int rr,int p);
    void sendHR(unsigned char hr,int p);
    void sendPerfustion(double perfusion,int p);

public:
    PPGRealProcess1(QObject *parent = nullptr);
    ~PPGRealProcess1();
    void initial();
    void StartCompute(double ir,double red);
    double lp_filter_red(double raw_red);
    double lp_filter_ir(double raw_ir);
    double lp_filter_ir_forCompute(double raw_ir);
    double hp_filter_red(double raw_red);
    double hp_filter_ir(double raw_ir);
    void updateHeartRate(unsigned char* rate, int last);
    void updateWindow(double* peakWindow, int len,double Y);
    void updateSPO2(double* SPO2, double lastOnsetValueIR, double lastOnsetValueRed, double lastPeakValueIR, double lastPeakValueRed);
    void updatepi(double lastOnsetValueIR, double lastPeakValueIR);
    unsigned char mean_BP(double* BP);
    unsigned char chooseRate(unsigned char* rate);
    double chooseSPox(double* ox);
    double findMax(double* X,int X_Len);
    double findMin(double* X,int X_Len);
    QList<int> getPeakPos();



};

#endif // PPGREALPROCESS1_H
